<template>
  <div class="bottom-charts">
    <div v-for="(item,index) in devices" :key="index" style="position:relative;flex:1">
      <div class="bc-chart-item" @click="showDevice(item.serialno)">
        <div class="bcci-header">{{ item && item.name || '' }}</div>
        <dv-active-ring-chart :config="getConfig(item)" />
      </div>
      <dv-decoration-2
        class="decoration-1"
        :reverse="true"
        style="width:5px;"
      />
    </div>
    <el-dialog
      v-el-drag-dialog
      append-to-body
      :title="deviceContainerTitle"
      :visible.sync="deviceContainerVisible"
      width="1360px"
      @close="dialogClose"
    >
      <span
        v-if="currentDevice"
        slot="title"
        class="device-header"
      >
        <el-image
          class="device-image"
          :src="getDeviceImage(currentDevice)"
          :fit="fit"
        />
        {{ currentDevice.name + ' —— ' + currentDevice.serialno }}
      </span>
      <sf />
      <qxz />
      <sqz />
      <cqz />
    </el-dialog>
    <mqtt-container
      ref="mqttContainer"
    />
  </div>
</template>

<script>
import MqttContainer from '@/components/MqttContainer'
import Sf from '@/components/Device/Sf'
import Qxz from '@/components/Device/Qxz'
import Sqz from '@/components/Device/Sqz'
import Cqz from '@/components/Device/Cqz'
import { mapGetters } from 'vuex'
import { getDeviceStatus, getDeviceImage } from '@/utils/device'
export default {
  name: 'BottomCharts',
  components: {
    MqttContainer,
    Qxz,
    Sqz,
    Sf,
    Cqz
  },
  props: {
    devices: {
      type: Array,
      default() {
        return {
          data: []
        }
      }
    }
  },
  data() {
    return {
      deviceContainerTitle: '设备控制',
      deviceContainerVisible: false,
      currentDevice: null,
      serialno: '',
      fit: 'fill'
    }
  },
  computed: {
    ...mapGetters(['devicesObj'])
  },
  methods: {
    getConfig(item) {
      return {
        data: item && item.states_datav || [],
        color: ['#00baff', '#3de7c9', '#fff', '#ffc530', '#469f4b'],
        radius: '65%',
        activeRadius: '70%',
        showOriginValue: true
      }
    },
    showDevice(serialno) {
      this.currentDevice = this.devicesObj[serialno]
      console.log(this.currentDevice)
      this.$store.commit('device/SET_CURRENT_DEVICE', this.currentDevice)
      this.$store.commit('device/SET_CURRENT_DEVICE_SHOW', true)
      this.serialno = serialno
      this.deviceContainerTitle = this.currentDevice.name
      this.deviceContainerVisible = true
    },
    getDeviceStatus(device) {
      return getDeviceStatus(device)
    },
    getDeviceImage(device) {
      return getDeviceImage(device)
    },
    dialogClose() {
      this.$store.commit('device/SET_CURRENT_DEVICE_SHOW', false)
    }
  }
}
</script>

<style lang="scss">
.bottom-charts {
  width: 100%;
  height: 100%;
  display: flex;
  position: relative;

  .bc-chart-item {
    width: 100%;
    height: 100%;
    padding-top: 16px;
    box-sizing: border-box;
    cursor: pointer;
  }

  .bcci-header {
    height: 80px;
    text-align: center;
    line-height: 80px;
    font-size: 20px;
  }

  .dv-active-ring-chart {
    height: calc(100% - 80px);
  }

  .label-tag {
    height: 30px;
  }

  .active-ring-name {
    font-size: 14px !important;
  }

  .decoration-1,
  .decoration-2,
  .decoration-3 {
    position: absolute;
    left: 0%;
    top: 2%;
  }
}
.device-header{
  font-size:16px;
  display:flex;
  align-items:center;
}
</style>
